<template>
  <div>
    <van-sticky :offset-top="0" class="van-sticky-box">
      <van-dropdown-menu v-show="!loading">
        <van-dropdown-item v-model="value" :options="list" @change="onSelect" />
      </van-dropdown-menu>
      <div v-show="loading" class="loading-box">
        <van-loading type="spinner" color="#1989fa" class="loading">加载中...</van-loading>
      </div>
    </van-sticky>
  </div>
</template>

<script>
import Vue from "vue";
import { Sticky, loading ,Toast} from "vant";
import listApi from "../../api/enterprise";
Vue.use(Sticky);
export default {
  data() {
    return {
      value: "",
      list: [],
      loading: true
    };
  },
  methods: {
    // getList() {
    //   return this.$Api
    //     .get(listApi.findCorpList, {})
    //     .then(response => {
    //       let res = response.data;
    //       if (res.code == 200) {
    //         if(typeof res.data =="string"){
    //           this.loading = false;
    //           Toast(res.data);
    //           return null;
    //         }
    //         this.list = res.data.records.map(item => {
    //           return {
    //             text: item.corpName,
    //             value: item.corpId
    //           };
    //         });
    //         if (this.value == "") {
    //           this.value = this.list[0].value;
    //         }
    //         this.loading = false;
    //         return this.value;
    //       }
    //     })
    //     .catch(error => {
    //       this.loading = false;
    //       return error;
    //     });
    // },
    onSelect(val) {
      this.$emit("select", this.value);
    }
  }
};
</script>

<style lang="less" scoped>
.loading-box {
  text-align: center;
}
</style>
